package org.yxj.changethemeapp.v

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager
import com.youth.banner.Banner
import org.yxj.changethemeapp.LogUtils

/**
 * @author  on 2024/6/25
 */
class MyBanner:Banner {

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet,0)
    constructor(context: Context, attrs: AttributeSet?, defStyle: Int):super(context, attrs, defStyle){
        setOnPageChangeListener(object : ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
                p = position
            }
            override fun onPageSelected(position: Int) {
                p = position
            }
            override fun onPageScrollStateChanged(state: Int) {
            }
        })
    }


    var p = 0
    var count = 0
    override fun onTouchEvent(ev: MotionEvent?): Boolean {
        ev?.let {
            when (it.action) {
                MotionEvent.ACTION_DOWN -> {
                    LogUtils.LOG_V("[childCount]-> childCount = $childCount")
                    LogUtils.LOG_V("[childCount]-> (p + 1) = $p")
                    parent.requestDisallowInterceptTouchEvent(true)
                }
                MotionEvent.ACTION_MOVE -> {
                }
                MotionEvent.ACTION_UP -> {
                    parent.requestDisallowInterceptTouchEvent(false)
                }
            }
        }
        return super.onTouchEvent(ev)
    }
}